public class Complex1 {
    public double getRealPart() {
        return RealPart;
    }

    public double getImagePart() {
        return ImagePart;
    }

    private double RealPart;
    private double ImagePart;

    public void setRealPart(double realPart) {
        RealPart = realPart;
    }

    public void setImagePart(double imagePart) {
        ImagePart = imagePart;
    }

    public Complex1() {
    }

    public Complex1(double R, double I) {
        this.ImagePart = I;
        this.RealPart = R;
    }


    @Override
    public String toString() {

        if (getImagePart() > 0) {
            return "(" + getRealPart() + "+" + getImagePart() + "i" + ")";
        } else {
            return "(" + getRealPart() + "-" + getImagePart() + "i" + ")";
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {

            return false;
        }
        Complex1 complex = (Complex1) o;
        return Double.compare(complex.getRealPart(), getRealPart()) == 0 &&
                Double.compare(complex.getImagePart(), getImagePart()) == 0;
    }

    Complex1 ComplexAdd(Complex1 a) {
        return new Complex1(this.RealPart + a.RealPart, this.ImagePart + a.ImagePart);
    }

    Complex1 ComplexSub(Complex1 a) {
        return new Complex1(this.RealPart - a.RealPart, this.ImagePart - a.ImagePart);
    }

    Complex1 ComplexMulti(Complex1 a) {
        return new Complex1(this.RealPart * a.RealPart - this.ImagePart * a.ImagePart,
                this.ImagePart * a.RealPart + this.RealPart * a.ImagePart);
    }

    Complex1 ComplexDiv(Complex1 a) {
        double scale = a.getRealPart() * a.getRealPart() + a.getImagePart() * a.getImagePart();
        Complex1 b = new Complex1(a.getRealPart() / scale, -a.getImagePart() / scale);
        return this.ComplexMulti(b);
    }
}
